<script>
export default {
  name: "rank",
  data() {
    return {
      rankList: [

      ]
    }
  },
  onShow() {
    this.$api.groupList().then(res => {
      console.log(res)
      this.rankList = res.map(item => {
        return {
          ...item,
          count: item.voteList.length
        }
      })
      // 排序从大到小
      this.rankList.sort((a, b) => {
        return b.count - a.count
      })
    })
  }
}
</script>

<template>
  <div class="rank">
    <div class="rank-box">
      <div class="rank-header">
        排行榜
      </div>
      <div class="rank-item" v-for="(item,index) in rankList" :key="item.id">
        <image class="rank-icon" v-if="index === 0" src="/static/rank1.png"></image>
        <image class="rank-icon" v-else-if="index === 1" src="/static/rank2.png"></image>
        <image class="rank-icon" v-else-if="index === 2" src="/static/rank3.png"></image>
        <div class="rank-icon rank-code" v-else>{{ index + 1}}</div>
        <image class="image" :src="item.url"></image>
        <div class="rank-content">
          {{ item.name }}
        </div>
        <div class="rank-count">
          {{ item.count }}票
        </div>
      </div>
    </div>
    <u-empty v-if="rankList.length === 0" style="margin-top: 200px" />

  </div>
</template>

<style  lang="scss">
pages {
  height: 100%;
}
.rank {
  position: relative;
  padding: 32rpx;
  padding-top: 60rpx;
  min-height: 100%;
  padding-bottom: 100rpx;

  background: linear-gradient( 180deg, #E4F6FF 0%, #F7F8FA 100%);
  background-size: cover;
  background-repeat: no-repeat;
}

.rank-box {
  width: 100%;
  border-radius: 32rpx;
  background-color: #ffffff;
  position: relative;
  padding-top: 120rpx;
  padding-bottom: 40rpx;
  .rank-item {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #f0f0f0;
    padding: 24rpx;
    .rank-icon {
      flex-shrink: 0;
      width: 52rpx;
      height: 52rpx;
      margin-right: 16rpx;
    }
    .rank-code {
      flex-shrink: 0;
      font-size: 32rpx;
      color: rgba(51,109,244,1);
      text-align: center;
      font-weight: bold;
    }
    .image {
      flex-shrink: 0;
      width: 80rpx;
      height: 80rpx;
      margin-right: 10rpx;
    }
    .rank-content {
      flex-grow: 1;
      display: flex;
      align-items: center;
      font-size: 32rpx;
      color: #999999;
      padding-right: 12rpx;
      padding-left: 20rpx;
    }
    .rank-count {
      font-size: 28rpx;
      color: #333333;
    }
  }
  .rank-item:last-child {
    border-bottom: none;
  }
}
.rank-header {
  background-color: #ffffff;
  border-top-left-radius: 16rpx;
  border-top-right-radius: 16rpx;
  height: 84rpx;
  width: 320rpx;
  position: absolute;
  left: 50%;
  top: -32rpx;
  transform: translateX(-50%);
  text-align: center;
  line-height: 80rpx;
  font-size: 40rpx;
  color: #ffffff;
  background-color: rgba(51,109,244,1);
}
</style>
